home *** CD-ROM | disk | FTP | other *** search
- #include "Protocol Mover.h"
- #include "Protocol.h"
-
- /*#define APPLUTIL {dummy}*/
-
- extern ProcMenuHandle PMH;
- extern Prefs thePrefs;
-
- int cancelCount;
-
- long tOne, tTwo, byteStart;
-
- int procLevel[PROCINDEX];
-
- DialogPtr Tdp = 0L;
- int (*ExtProc)() = 0L;
-
- #define tdCANCELBUT 1
- #define tdSTATUS 2
- #define tdERROR 3
- #define tdMBNAME 4
- #define tdMREFIN 5
- #define tdMREFOUT 6
- #define tdPROCID 7
- #define tdFLAGS 8
- #define tdFILESDONE 9
- #define tdBYTESDONE 10
- #define tdBYTESTOTAL 11
- #define tdCPS 12
- #define tdTIMEIN 13
- #define tdTIMEOUT 14
- #define tdDIRID 15
- #define tdFILEID 16
- #define tdVREFNUM 17
- #define tdSLINE1 34
- #define tdSLINE2 35
- #define tdSLINE3 36
- #define tdSLINE4 37
- #define tdSLINE5 38
- #define tdSLINE6 39
-
- initProcLevel()
- {
- register int i;
- for (i = 0; i<PROCINDEX; i++) {
- procLevel[i] = 0;
- }
- }
-
- doTdialog(eptr)
- EventRecord *eptr;
- {
- int i, item;
- DialogPtr dp;
- if (DialogSelect(eptr, &dp, &item)) {
- if (dp == Tdp) {
- /* check for cancel */
- if (item == tdCANCELBUT) {
- if (cancelCount) {
- /* drop "carrier" and dim button */
- (*(*PMH)->transData)->F.B.carrierLost = TRUE;
- ActItem(tdCANCELBUT, FALSE, Tdp);
- }
- else {
- /* signal transfer to cancel and change button */
- (*(*PMH)->transData)->F.B.stopTrans = TRUE;
- SetCtlTitle(tdCANCELBUT, "\pEXIT", Tdp);
- ++cancelCount;
- }
- }
- }
- }
- }
-
- showTdialog()
- {
- OsErr err;
- Rect aRect;
- Handle pHand;
- GrafPtr savePort;
- int i, resSave, pID;
- register ProtoRecPtr prp;
- pascal void flashyStuff();
- if (PMH && (*PMH)->transData && !Tdp) {
- tOne = tTwo = 0;
- prp = *(*PMH)->transData;
- /* save the current resource file */
- resSave = CurResFile();
- /* set the resource file to the Transfer Protocols */
- UseResFile(thePrefs.rRef);
- /* get the PROC resource */
- pID = (*PMH)->pList[(*PMH)->transIndex].procID;
- pHand = Get1Resource('PROC', pID);
- /* restore the resource file */
- UseResFile(resSave);
- if (pHand) {
- /* lock the PROC down if it is not being used... for this
- example code this is not really needed, the need comes
- about in multiport systems where the same transfer PROC
- might be running on two different ports. In this case
- it might already be locked down by "someone else".
- */
- if (!(procLevel[(pID-1000)/100]++)) {
- /* move it up to help stop fragging */
- MoveHHi(pHand);
- /* lock it down for the duration */
- HLock(pHand);
- }
- if ((*PMH)->transMessage == SETPREFS) {
- /* let's take care of it here */
- /* prp->mRefIn, mRefOut, timeOut to be filled out by
- caller... so let's do it!
- */
- prp->mRefIn = 0;
- prp->mRefOut = 0;
- prp->timeOut = 10;
- /* get a pointer to it */
- ExtProc = (int (* )()) *pHand;
- /* get it over with */
- /* set the resource file to the Transfer Protocols */
- UseResFile(thePrefs.rRef);
- do {
- err = CallPascalW((*PMH)->transMessage, *(*PMH)->transData,
- (*PMH)->transRefCon, ExtProc);
- } while (!err);
- /* restore the resource file */
- UseResFile(resSave);
- /* show a MacOs Error (if there) */
- ErrorBox(err);
- /* Unlock the PROC if it is not being used anymore...for
- this example code this is not really needed, the need
- comes about in multiport systems where the same
- transfer PROC might be running on two different ports.
- In this case it might be still running somewhere else,
- and therefore it must remain locked.
- */
- pID = (*PMH)->pList[(*PMH)->transIndex].procID;
- if (!(--procLevel[(pID-1000)/100])) {
- /* PROC is marked purgable so we do not have to dispose
- of it
- */
- HUnlock(RecoverHandle(ExtProc));
- }
- /* signal no more calls */
- ExtProc = 0L;
- /* dispose of the file info data structure */
- Utility(DISPOSEPREC, PMH, 0L);
- }
- else {
- /* prp->mRefIn, mRefOut, timeOut to be filled out by
- caller... so let's do it!
- */
- prp->mRefIn = thePrefs.mRefIn;
- prp->mRefOut = thePrefs.mRefOut;
- prp->timeOut = 10;
- /* get a pointer to it */
- ExtProc = (int (* )()) *pHand;
- /* reset the cancel button count */
- cancelCount = 0;
- /* get the dialog and set the dialog's port up */
- GetPort(&savePort);
- SetDAFont(geneva);
- Tdp = GetNewDialog(129, 0L, -1L);
- SetDAFont(systemFont);
- SetPort(Tdp);
- TextSize(9);
- GetItemRect(tdSLINE1, &aRect, Tdp);
- SetDItem(Tdp, tdSLINE1, userItem, flashyStuff, &aRect);
- SetPort(savePort);
- /* set up some items */
- SetNumberItem(tdMREFIN, (long) prp->mRefIn, Tdp);
- SetNumberItem(tdMREFOUT, (long) prp->mRefOut, Tdp);
- SetNumberItem(tdPROCID, (long) pID, Tdp);
- setFStats(0);
- byteStart = 0L;
- /* disable all menus */
- for (i = 2; i<=TransferID; i++) {
- EDMenuItem(i, 0, FALSE);
- }
- DrawMenuBar();
- }
- }
- }
- }
-
- doTransPROC()
- {
- OsErr err;
- long cps;
- int resSave, pID, i;
- register ProcMenuPtr pmp;
- register ProtoRecPtr prp;
- if (ExtProc) {
- prp = *(*PMH)->transData;
- /* save the current resource file */
- tOne = TickCount();
- resSave = CurResFile();
- /* set the resource file to the Transfer Protocols */
- UseResFile(thePrefs.rRef);
- /* call the proc...dispose the dialog if we have an error */
- pmp = *PMH;
- err = CallPascalW(pmp->transMessage, *pmp->transData,
- pmp->transRefCon, ExtProc);
- /* restore the resource file */
- UseResFile(resSave);
- /* update the transfer dialog */
- SetNumberItem(tdFLAGS, (long) prp->F.word, Tdp);
- if (prp->F.B.Recovering) {
- byteStart = prp->bytesDone;
- prp->F.B.Recovering = FALSE;
- }
- if (prp->F.B.newError) {
- HLock(prp->errReason);
- SetTextItem(tdERROR, *prp->errReason, Tdp);
- if (err) {
- /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- /* record error in transfer log */
- /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- }
- HUnlock(prp->errReason);
- DisposHandle(prp->errReason);
- prp->errReason = 0L;
- prp->F.B.newError = FALSE;
- }
- if (prp->F.B.newFile) {
- /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- /* record transfer in log and update user stats */
- /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
- prp->F.B.newFile = FALSE;
- prp->bytesDone = 0L;
- prp->bytesTotal = 0L;
- setFStats(prp->filesDone+1);
- byteStart = 0L;
- }
- if (prp->F.B.newMBName) {
- setFStats(prp->filesDone);
- prp->F.B.newMBName = FALSE;
- }
- SetNumberItem(tdFILESDONE, (long) prp->filesDone, Tdp);
- SetNumberItem(tdBYTESDONE, (long) prp->bytesDone, Tdp);
- SetNumberItem(tdBYTESTOTAL, (long) prp->bytesTotal, Tdp);
- cps = (prp->bytesDone-byteStart)*60;
- cps /= TickCount()-prp->startTime+1;
- SetNumberItem(tdCPS, (long) cps, Tdp);
- SetNumberItem(tdTIMEOUT, (long) (tOne - tTwo), Tdp);
- tTwo = TickCount();
- SetNumberItem(tdTIMEIN, (long) (tTwo - tOne), Tdp);
- if (err) {
- /* close the transfer dialog */
- SysBeep(3);
- Delay(120L, &tTwo);
- DisposDialog(Tdp);
- /* signal the dialog is gone */
- Tdp = 0L;
- /* enable all menus */
- for (i = 2; i<=TransferID; i++) {
- EDMenuItem(i, 0, TRUE);
- }
- DrawMenuBar();
- /* show a MacOs Error (if there) */
- ErrorBox(err);
- /* Unlock the PROC if it is not being used anymore...for this
- example code this is not really needed, the need comes
- about in multiport systems where the same transfer PROC
- might be running on two different ports. In this case it
- might be still running somewhere else, and therefore it
- must remain locked.
- */
- pID = (*PMH)->pList[(*PMH)->transIndex].procID;
- if (!(--procLevel[(pID-1000)/100])) {
- /* PROC is marked purgable so we do not have to dispose of it */
- HUnlock(RecoverHandle(ExtProc));
- }
- /* signal no more calls */
- ExtProc = 0L;
- /* dispose of the file info data structure */
- Utility(DISPOSEPREC, PMH, 0L);
- }
- }
- else if (thePrefs.mode == TERMINALMODE) {
- checkAutoReceive();
- }
- }
-
- setFStats(index)
- int index;
- {
- Str255 text1, text2;
- register ProtoRecPtr prp;
- text2[0] = 0;
- prp = *(*PMH)->transData;
- if (index < prp->fileCount) {
- if ((*PMH)->transMessage == SEND) {
- Pstrcpy(text1, "\pSending ā");
- }
- else {
- Pstrcpy(text1, "\pReceiving ā");
- }
- Pstrcat(text1, *prp->fList[index].fName);
- Pstrcat(text1, "\pā by ");
- Pstrcat(text1, *(*PMH)->pList[(*PMH)->transIndex].subName);
- SetNumberItem(tdVREFNUM, (long) prp->fList[index].vRefNum, Tdp);
- SetNumberItem(tdDIRID, prp->fList[index].dirID, Tdp);
- SetNumberItem(tdFILEID, prp->fList[index].fileID, Tdp);
- if (prp->fList[index].mbName) {
- Pstrcpy(text2, *prp->fList[index].mbName, Tdp);
- }
- }
- else {
- text1[0] = 0;
- SetTextItem(tdVREFNUM, text1, Tdp);
- SetTextItem(tdDIRID, text1, Tdp);
- SetTextItem(tdFILEID, text1, Tdp);
- Pstrcpy(text1, "\pFinishing Transfer");
- }
- SetTextItem(tdSTATUS, text1, Tdp);
- SetTextItem(tdMBNAME, text2, Tdp);
- }
-
- static pascal void flashyStuff(dp, item)
- DialogPtr dp;
- int item;
- {
- Rect aRect;
- PenPat(*((Handle) CurrentA5)-24);
- GetItemRect(tdSLINE1, &aRect, dp);
- FrameRect(&aRect);
- GetItemRect(tdSLINE2, &aRect, dp);
- FrameRect(&aRect);
- GetItemRect(tdSLINE3, &aRect, dp);
- FrameRect(&aRect);
- GetItemRect(tdSLINE4, &aRect, dp);
- FrameRect(&aRect);
- GetItemRect(tdSLINE5, &aRect, dp);
- FrameRect(&aRect);
- GetItemRect(tdSLINE6, &aRect, dp);
- FrameRect(&aRect);
- PenNormal();
- }
-
- checkAutoReceive()
- {
- OsErr err;
- char theChar;
- register int i;
- register AutoComPtr acpSave;
- register unsigned char *acp;
- long bytesAvail, count;
- if (thePrefs.currentPort != -1) {
- SerGetBuf(thePrefs.mRefIn, &bytesAvail);
- if (bytesAvail) {
- count = 1;
- err = FSRead(thePrefs.mRefIn, &count, &theChar);
- /* of course a real terminal program would have to actually
- do something with the characters it gets but we don't...
- */
- if (!err) {
- acp = (unsigned char *) *(*PMH)->autoComs;
- for (i = 0; i<(*PMH)->autoCount; i++) {
- acpSave = (AutoComPtr) acp;
- /* bump past the non-string stuff */
- acp = (unsigned char *) (&(((AutoComPtr) acp)->autoCom));
- if (*(acp + acpSave->matchChar) == theChar) {
- ++acpSave->matchChar;
- if (acpSave->matchChar > *acp) {
- /* we have a match */
- Utility(DOMENU, PMH, acpSave->menuSelect);
- showTdialog();
- /* clear all matchChars */
- acp = (unsigned char *) *(*PMH)->autoComs;
- for (i = 0; i<(*PMH)->autoCount; i++) {
- ((AutoComPtr) acp)->matchChar = 1;
- /* bump past the non-string stuff */
- acp = (unsigned char *)
- (&(((AutoComPtr) acp)->autoCom));
- /* bump past the auto string (with padding) */
- acp += *acp+2-(*acp & 1);
- }
- /* break out of the loop */
- break;
- }
- }
- else {
- acpSave->matchChar = 1;
- }
- /* bump past the auto string (with padding) */
- acp += *acp+2-(*acp & 1);
- }
- }
- }
- }
- }
-
- OsErr Utility(message, prp, refCon)
- register int message;
- register ProtoRecPtr prp;
- long refCon;
- {
- int resSave;
- Handle pHand;
- if (thePrefs.rRef != -1) {
- /* save the current resource file */
- resSave = CurResFile();
- /* set the resource file to the Transfer Protocols */
- UseResFile(thePrefs.rRef);
- #ifndef APPLUTIL
- /* get the PROC resource */
- pHand = Get1Resource('PROC', 900);
- if (pHand) {
- MoveHHi(pHand);
- HLock(pHand);
- ErrorBox(CallPascalW(message, prp, refCon, ((int (* )()) *pHand)));
- HUnlock(pHand);
- }
- #else
- {
- pascal OsErr UtilityMain();
- ErrorBox(CallPascalW(message, prp, refCon, UtilityMain));
- }
- #endif
- /* restore the resource file */
- UseResFile(resSave);
- }
- }
-